<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var relativeSortArray = function (arr1, arr2) {
      return arr1.sort((a, b) => {
        let ia = arr2.indexOf(a);
        let ib = arr2.indexOf(b);
        if (ia == -1 && ib == -1) {
          return a - b;
        } else if (ia == -1) {
          return 1;
        } else if (ib == -1) {
          return -1;
        } else {
          return ia - ib;
        }
      });
    };  
    console.log(relativeSortArray(arr1 = [2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], arr2 = [2, 1, 4, 3, 9, 6]));
  </script>
</body>

</html>